﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Hkwl.WorldExpo.Merchant.Common;
using Hkwl.WorldExpo.Merchant.Model;
using Hkwl.WorldExpo.Merchant.Service;
using System.Collections.Generic;

namespace Hkwl.WorldExpo.Merchant.Web
{
    public partial class MMSView : BaseCheckPage
    {
        public int mmsId =0;
        public int projectId=0;
        protected void Page_Load(object sender, EventArgs e)
        {
            mmsId = int.Parse(Request.QueryString["MmsId"]);
            projectId = int.Parse(Request.QueryString["ProjectId"]);
            NxMms nxMms = ServiceLocator.IProjectService.GetNxMmsById(mmsId);
            NxProject nxProject = ServiceLocator.IProjectService.GetNxProjectById(projectId);
            IList<NxMms> nxMMS = ServiceLocator.IProjectService.GetNxMmsCollection(projectId);
            this.lbMSSTitle.Text = nxProject.MmsTitle;
            if (nxMms.MmsPic != null)
            {
                this.lbMmsPosition.Text = nxMms.MmsPosition == 1 ? (String)GetLocalResourceObject("String1") : (String)GetLocalResourceObject("String2");
            }
            else
            {
                this.lbMmsPosition.Text = (String)GetLocalResourceObject("String3");
            }
            
            
            this.lbDelayTime.Text = nxMms.DelayTime.ToString();
            this.lbMmsPage.Text = nxMms.MmsPage.ToString();
            this.lbMmsPageCount.Text = nxMMS.Count.ToString();
            if (nxMms.MmsPage > 1)
            { 
                this.btnPrevPage.Visible = true;
            }
            if (nxMMS.Count > 1 && nxMMS.Count > nxMms.MmsPage)
            {
                this.btnNextPage.Visible = true;
            }
        }

        protected void btnModify_Click(object sender, EventArgs e)
        {
            Response.Redirect("ModifyMMS.aspx?MmsId="+mmsId+"&ProjectId="+projectId);
        }

        protected void btnCreateNextPage_Click(object sender, EventArgs e)
        {
            Response.Redirect("MMSCreate.aspx?MmsPage=" + (int.Parse(lbMmsPageCount.Text)+1).ToString() + "&ProjectId=" + projectId);
        }

        protected void btnSaveMMS_Click(object sender, EventArgs e)
        {
            Response.Redirect("ProjectList.aspx");
        }

        protected void btnNextPage_Click(object sender, EventArgs e)
        {
            NxMms mms = ServiceLocator.IProjectService.GetNxMmsByPage(projectId,int.Parse(this.lbMmsPage.Text) + 1);
            Response.Redirect("MMSView.aspx?MmsId=" + mms.MmsId + "&ProjectId=" + projectId);
        }

        protected void btnPrevPage_Click(object sender, EventArgs e)
        {
            NxMms mms = ServiceLocator.IProjectService.GetNxMmsByPage(projectId, int.Parse(this.lbMmsPage.Text) - 1);
            Response.Redirect("MMSView.aspx?MmsId=" + mms.MmsId + "&ProjectId=" + projectId);
        }
    }
}
